package shaka.core

import junit.framework.JUnit4TestAdapter

import org.junit.Test

public class TestBean {
	public static junit.framework.Test suite() {
		return new JUnit4TestAdapter(TestBean.class)
	}

	class Arg1 {
		int k1
		int k2
		String k3
	}

	@Test
	public void run1() {
		def args = new Arg1(
				k1:100,
				k2:200,
				k3:null)
		assert args.k1 == 100
		assert args.k2 == 200
		assert args.k3 == null

		args << null
		assert args.k1 == 100
		assert args.k2 == 200
		assert args.k3 == null

		args << [k1:1, k3:'Super Man']
		assert args.k1 == 1
		assert args.k2 == 200
		assert args.k3 == 'Super Man'

		assert args as Map == [k1:1, k2:200, k3:'Super Man']
	}

	@Test
	public void run2(){
		def args = [
			k1:100,
			k2:200]

		args << null
		assert args.k1 == 100
		assert args.k2 == 200

		args << [k1:1]
		assert args.k1 == 1
		assert args.k2 == 200
	}

	@Test
	public void run3(){
		assert isEmpty(null) == true
		assert isEmpty('') == true
		assert isEmpty([]) == true
		assert isEmpty([:]) == true
		assert isEmpty('test') == false
		assert isEmpty([1, 2, 3]) == false
		assert isEmpty([k1:1]) == false
		assert isEmpty(new Object()) == false
	}

	@Test
	public void run4(){
		assert isNotEmpty(null) == false
		assert isNotEmpty('') == false
		assert isNotEmpty([]) == false
		assert isNotEmpty([:]) == false
		assert isNotEmpty('test') == true
		assert isNotEmpty([1, 2, 3]) == true
		assert isNotEmpty([k1:1]) == true
	}

	@Test
	public void run5(){
		def args = new Arg1(
				k1:100,
				k2:200)
		assert prop(args, 'k1') == 100
		assert prop(args, 'k3') == null
		assert prop(args, 'k1', 999) == 100
		assert prop(args, 'k3', '999') == '999'

		assert prop(obj:args, propName:'k1') == 100
		assert prop(obj:args, propName:'k3') == ''
		assert prop(obj:args, propName:'k1', defValue:999) == 100
		assert prop(obj:args, propName:'k3', defValue:'999') == '999'

		args = null
		assert prop(args, 'k1', 999) == 999
		assert prop(args, 'k3', '999') == '999'
		assert prop(obj:args, propName:'k1', defValue:999) == 999
		assert prop(obj:args, propName:'k3', defValue:'999') == '999'
	}

	@Test
	public void run6(){
		def args = [k1:100,k2:200]
		assert prop(args, 'k1') == 100
		assert prop(args, 'k3') == null
		assert prop(args, 'k1', 999) == 100
		assert prop(args, 'k3', '999') == '999'

		args = null
		assert prop(args, 'k1', 999) == 999
		assert prop(args, 'k3', '999') == '999'
	}
}
